package com.TinyBBS.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.TinyBBS.model.GameModel;

/**
 * Servlet implementation class Games
 */
public class Games extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String uri = "game.jsp";
		String error = "";
		try {
			GameModel gameM = new GameModel();
			List gameList = gameM.getAllGame();
			if (gameList.equals(null) == true) {
				error = "Failed to access database";
			} else {
				request.setAttribute("gamelist", gameList);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		request.setAttribute("error", error);
		request.getRequestDispatcher(uri).forward(request, response);

	}

}
